package com.daisuxia.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.daisuxia.back.service.AdvertisementService;
import com.daisuxia.web.pojo.Advertisement;

@Controller
@RequestMapping("ad/")
public class AdvertisementController {
	@Autowired
	private AdvertisementService adService;
	
	@RequestMapping("getAd")
	@ResponseBody
	public Object list(HttpServletRequest request) {
		String code = "0";
		String msg = "success";
		Map<String, Object> data = new HashMap<String, Object>();
		Map<String, Object> map = new HashMap<String, Object>();
		List<Advertisement> all = adService.findAll();
		if (all == null || all.isEmpty()) {
			code = "-1";
			msg = "fail";
		} else {
			Advertisement ad = all.get(0);
			data.put("tcImage", ad.getUrl());
			data.put("tcUrl", ad.getReurl());
			data.put("tcStatus", ad.getStatus());
			if(request.getParameter("clientType").equals("android")){
				data.put("type","0");
			}else {
				data.put("type","-1");
			}
		}
		map.put("code", code);
		map.put("message", msg);
		map.put("data", data);
		return map;
	}

}
